package cn.usts.edu.lesson06;

/**
 * 模拟延时,放大问题
 * */
public class ThreadSleepDemo implements Runnable{
    private int tickets =10; // 设置10张票

    @Override
    public void run() {
        while (true){
            if (tickets>0){
                System.out.println(Thread.currentThread().getName()+"拿到了票号-----+"+tickets--);
            }
            else {
                break;
            }
            try {
                Thread.sleep(200);//模拟网络延迟200ms
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }



    }

    // 模拟三个人抢票
    public static void main(String[] args) {
        ThreadSleepDemo t = new ThreadSleepDemo();
        new Thread(t,"小红").start();
        new Thread(t,"小明").start();
        new Thread(t,"黄牛").start();
    }


}
